package com.tourismhengyang.impl;

import java.io.IOException;
import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.tourismhengyang.beans.LocalInfo;
import com.tourismhengyang.biz.ILocalInfoBiz;
import com.tourismhengyang.dao.DBAccess;

public class LocalInfoBizImpl implements ILocalInfoBiz{
	private DBAccess db=new DBAccess();
	@Override
	public int addLocalInfo(LocalInfo localInfo) {
		SqlSession session = null;
		int result=0;
		try {
			session=db.getSqlSession();
			ILocalInfoBiz localInfoBiz=session.getMapper(ILocalInfoBiz.class);
			result=localInfoBiz.addLocalInfo(localInfo);
			session.commit();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			session.close();
		}
		return result;
	}
	
	@Override
	public List<LocalInfo> getLocalInfoList() {
		SqlSession session = null;
		List<LocalInfo> result=null;
		try {
			session=db.getSqlSession();
			ILocalInfoBiz localInfoBiz=session.getMapper(ILocalInfoBiz.class);
			result=localInfoBiz.getLocalInfoList();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			session.close();
		}
		return result;
	}

	@Override
	public List<LocalInfo> getLids() {
		SqlSession session = null;
		List<LocalInfo> result=null;
		try {
			session=db.getSqlSession();
			ILocalInfoBiz localInfoBiz=session.getMapper(ILocalInfoBiz.class);
			result=localInfoBiz.getLids();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			session.close();
		}
		return result;
	}

	@Override
	public LocalInfo getInfoByLid(int lid) {
		SqlSession session = null;
		LocalInfo result = null;
		try {
			session=db.getSqlSession();
			ILocalInfoBiz localInfoBiz = session.getMapper(ILocalInfoBiz.class);
			result = localInfoBiz.getInfoByLid(lid);
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			session.close();
		}
		return result;
	}

	@Override
	public List<LocalInfo> getSearchInfo(String lname) {
		SqlSession session = null;
		List<LocalInfo> result=null;
		try {
			session=db.getSqlSession();
			ILocalInfoBiz localInfoBiz=session.getMapper(ILocalInfoBiz.class);
			result=localInfoBiz.getSearchInfo(lname);
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			session.close();
		}
		return result;
	}
}
